﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Proggy.Web.Cms.Extensions.Html
{
    /// <summary>
    /// Front-end editor extensions
    /// </summary>
    public static class ProggyInlineEditorExtensions
    {
        /// <summary>
        /// Begin inline editor
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static ProggyInlineEditor BeginProggyInlineEditor(this HtmlHelper html)
        {
            return inlineEditorHelper(html);
        }

        private static ProggyInlineEditor inlineEditorHelper(this HtmlHelper html)
        {
            // start tag builder
            var tagBld = new TagBuilder("div");
            tagBld.AddCssClass("proggy-inline-editor");
            tagBld.Attributes.Add(new KeyValuePair<string, string>("style", "border: 1px solid #ccc; padding: 1em;"));

            // write
            html.ViewContext.Writer.Write(tagBld.ToString(TagRenderMode.StartTag));

            // end 
            return new ProggyInlineEditor(html.ViewContext.Writer);
        }
    }
}
